/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module rptmerch.c - Multiple Merchant Report functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Merch/rptmerch.c $ 

**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#include <project.h>
#define RPTMERCH_C

#include <stdlib.h>
#include <stdio.h>
#include <applidl.h>
#include <aclconio.h>
#include <acldev.h>
#include <svctxo.h>
#include <dbmgr.h>
#include <formater.h>
#include <txoinc.h>
#include <aclstr.h>
#include <string.h>


/** /#define DEBUG_RPTMERCH*/
#ifdef DEBUG_RPTMERCH
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <rptmerch.h>
#include <batmsg.h>
#include <mit.h>
#include <tblutil.h>
#include <tct.h>
#include <pct.h>
#include <msg.h>
#include <entry.h>
#include <ui.h>
#include <print.h>
#include <msgfuncs.h>
#include <form.h>
#include <hdt.h>
#include <form2.h>
#include <mht.h>
#include <report.h>
#include <pbatch.h>
#include <spdebug.h>
#include <lct.h>
#include <codesec.h>

/********************************************************************************************* 
* @func int | inMerchTableReportOperation | 
*       Checks the printer and gets the template to print the merchant report. 
*
* @parm TRANSACTION_OBJECT *    | pobTran | 
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/

int inMerchTableReportOperation(TRANSACTION_OBJECT* pobTran) {
    int inRetVal;

    /** / pdebug(("--inMerchTableReportOperation--")); */

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        inRetVal = VS_SUCCESS;
    } else if (!fGetEnablePrinter())
        inRetVal = VS_SUCCESS;
    else {
        inGetReportMerTemplate();
        inRetVal = inPrintMerchTableReport(pobTran, &obPrinter);
    }

    return (inRetVal);
}

/********************************************************************************************* 
* @func int | inGetReportMerTemplate | 
*       Set the merchant report template to the active template.
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/

int inGetReportMerTemplate() {
    int inRetVal;
    char szTemplateFileName[FILENAME_SIZE + 1];

    strcpy(szTemplateFileName, STATIC_DATA_PATH);
    strcat(szTemplateFileName, szGetMerchReportNamePrefix());
    strcat(szTemplateFileName, szGetTemplateFileNameSuffix());

    if (inSwitchTemplate(szTemplateFileName) < 0) {
        vdDisplayMessageFromFile(FORMATER_ERR_MSG, ERROR_MSG);
        inRetVal = VS_ERR;
    } else
        inRetVal = VS_SUCCESS;

    return(inRetVal);
} 

/********************************************************************************************* 
* @func int | inPrintMerchTableReport | 
*       Print the merchant table report. 
*
* @parm TRANSACTION_OBJECT *    | pobTran | 
* @parm PRINTER_OBJECT *        | obPrinter |
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/

int inPrintMerchTableReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int inCnt1;
    long lnCondition = 0L;
    VS_BOOL fFileExists = VS_FALSE;


    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    vdMakeReportHeader(pobTran);
    if (inGetMITTotRecs() == 1)
        inPrintReceiptHeader(pobTran);
    if (inPrintLines(obPrinter, MERCH_TABLE_TOP_START, MERCH_TABLE_TOP_END, NO_BL_LINE, (fGetDemoMode() ? 1L : 0L)) != VS_SUCCESS)
        return(VS_ERR);

    /* load and print merchant table report information */
    for (inCnt1 = 0; inCnt1 < inGetMITTotRecs(); inCnt1++) {
        inLoadMITRec(inCnt1);
        sprintf(srRcpt.unFrm.srMerch.szMerchantNum, SUBSTITUTE_D, inGetMerchantNum());
        strcpy(srRcpt.unFrm.srMerch.szMerchantName, szGetMerchantText());
        pad(srRcpt.unFrm.srMerch.szMerchantName, srRcpt.unFrm.srMerch.szMerchantName, ' ', MESSAGE_SIZE, LEFT);

        if (inPrintLines(obPrinter, MERCH_TABLE_MIDDLE_START, MERCH_TABLE_MIDDLE_END, NO_BL_LINE, lnCondition) != VS_SUCCESS)
            return(VS_ERR);
    }

    if (inPrintLines(obPrinter, MERCH_TABLE_FORM_FEED, MERCH_TABLE_FORM_FEED, NO_BL_LINE, lnCondition) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

int RPTMERCH_CODE_CHECK(char* a,char* b,short* c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}



#undef RPTMERCH_C
